home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
turbovis
/
fsserial.zip
/
SERIAL.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-01-27
|
25KB
|
791 lines
Unit Serial;
{ SERIAL.PAS - 14 Jan 91
15 Jan 91 (Last Modification)
This unit is designed to allow the user to use a FOSSIL driver for
a serial unit that is event-driven aware. To do this, the input
from the modem is given an event status number just like the mouse or
keyboard. All input is then routed directly through the event driver
for all your dialogs to use. The output to the modem is in the form
of a series of events that you can use or direct calls via an object.
Note that these calls are the basics and do not halt for buffer
overruns in either Tx or Rx. Your application program will have to
monitor the serCarrier and serTxBuffer events to keep track if there
is a carrier or if there is room in the TX buffer for more to be
sent.
Note that this unit was written to take advantage of many of the
FOSSIL drivers out on the market such as X00.SYS or BNU.COM. If
the system does not detect a FOSSIL driver in memory, then it
resorts to standard interrupt driven serial I/O without the ability
to open up more than one port at a time. (Currently... This may
change in the future)
----------------
REVISION HISTORY
----------------
01-14-91 Designed and created the test version of the FOSSIL only
version. The internal serial routines have not yet been
written to be used with this Unit. Created the Event evSerial.
Added a bunch of BASIC routines to the serial driver and made sure
that the FSerial.Idle routine was passing the correct stuff!
01-15-91 Added Event checks for Carrier and Transmission Buffer
overflow.
01-22-91 Rearranged the LSList system as a TCollection to improve
the disposal procedure. Also created the serCarrierReq and
serTxBufferReq events so that the user can request a port status in
case for some reason he missed the toggle event.
01-27-91 Created a command entry to return a string if the receive
buffer has several characters in it insted of trying to send
each and every one via an event. Also changed the SERIAL.PAS activated
events to seperate procedures so that you can call them directly if you
inherit the Object or use it seperatly. There is also a procedure to
disable this system from creating Command events. You can use it
either way now...
}
{$F+,O+,R-,S-}
{$DEFINE FOSSILDRIVER} {This will check if a FOSSIL driver is in place and
will install a standard serial port if the driver
is not in memory. If this is undefined, then the
FOSSIL routines are not compiled in and you use the
standard Serial routines regardless}
{ DEFINE SERIALDRIVER} {If this is undefined, then all the standard serial
routines are left out. If the FOSSIL driver is not
in memory then you are out of luck...}
Interface
Uses Dos, Drivers, Views, Objects;
{----------------------------------------------------------------------------}
CONST evSerial = $8000; {Define a Serial Event Message}
stDupSerial = 195; {Duplicate Port Requested}
stOpenError = 194; {Error opening the port}
stInvalidPort = 193; {Invalid port number}
stInvalidBaud = 192; {Invalid selected baud rate}
stCharUnavail = 191; {Tried to read a char, but none available}
serBaud = 7100; {Set Baud Rate (Port,Baud)}
{Fmt: InfoByte=Port, InfoLong=+Baud SHL 16}
serSend = 7101; {Send a char (Port,Byte)}
{Fmt: InfoByte=Port, InfoWord=+Byte SHL 8}
serInit = 7104; {Initialize a port (Port)}
serDeInit = 7105; {Remove a port (Port)}
serRaiseDTR = 7106; {Raise the DTR (Port)}
serLowerDTR = 7107; {Lower the DTR (Port)}
serPurgeRx = 7108; {Purge the Recv buf (Port)}
serPurgeTx = 7109; {Purge output buf (Port)}
serFlow = 7115; {Set Flow Control (Port,Flow)}
{Fmt: InfoByte=Port, InfoWord=+Flow SHL 8}
serCarrierReq = 7116; {Request the Carrier Status (Port)}
serTxBufferReq= 7117; {Request Tx Buffer Status (Port)}
serEventGenOn = 7118; {Turn on Serial Event Generation}
serEventGenOff= 7119; {Turn off Serial Event Generation}
serCarrier = 7120; {Carrier Status (Port,Status)}
serTxBuffer = 7121; {TxBuffer Status (Port,Status)}
serRecvChar = 7122; {Received a char (Port,Byte)}
serRecvLine = 7123; {Received a line (Port,Ptr -> String)}
{----------------------------------------------------------------------------}
TYPE FossilList = RECORD
strsiz : WORD;
majver : BYTE;
minver : BYTE;
ident : POINTER;
ibufr : WORD;
ifree : WORD;
obufr : WORD;
ofree : WORD;
swidth : BYTE;
sheight : BYTE;
baud : BYTE;
END;
TYPE PTypes = (SerNone,SerStd,SerFossil);
PSList = ^LSList;
LSList = OBJECT(TObject)
SerialPort : BYTE;
PortType : PTypes;
BaudBits : BYTE;
FlowControl : BYTE;
Carrier : BOOLEAN;
TxBuffer : BOOLEAN;
CONSTRUCTOR Init(Port : BYTE);
CONSTRUCTOR Load(VAR S : TStream);
PROCEDURE Store(VAR S : TStream);
DESTRUCTOR Done; VIRTUAL;
END;
RecvRec = RECORD
Port : BYTE;
St : STRING
END;
TYPE PSerial = ^FSerial;
FSerial = OBJECT(TView)
OpenPorts : PCollection;
LastPort : BYTE;
EventGenerate : BOOLEAN;
{$IFDEF FOSSILDRIVER}
FossilUsed : BOOLEAN;
FossilInfo : FossilList;
{$ENDIF}
ErrorInfo : INTEGER;
CONSTRUCTOR Init;
CONSTRUCTOR Load(VAR S : TStream);
PROCEDURE Store(VAR S : TStream);
PROCEDURE InitPort(Port : BYTE);
PROCEDURE RemovePort(Port : BYTE);
PROCEDURE SetBaud(Port : BYTE; Baud : WORD);
PROCEDURE PurgeOutputBuf(Port : BYTE);
PROCEDURE PurgeInputBuf(Port : BYTE);
PROCEDURE SendChar(Port : BYTE; Ch : BYTE);
PROCEDURE SendLine(Port : BYTE; Ln : STRING);
FUNCTION RecvChar(Port : BYTE) : CHAR;
PROCEDURE DTRState(Port : BYTE; UpDown : BOOLEAN);
PROCEDURE FlowControl(Port : BYTE; Item : BYTE);
PROCEDURE SerialRequest(ReqType : WORD; Port : BYTE);
PROCEDURE GenerateEvents(Action : BOOLEAN);
PROCEDURE Reset;
DESTRUCTOR Done; VIRTUAL;
PROCEDURE Idle; VIRTUAL;
PROCEDURE HandleEvent(VAR Event : TEvent); VIRTUAL;
END;
CONST RSerial: TStreamRec = (
ObjType: 7100;
VmtLink: Ofs(TypeOf(FSerial)^);
Load: @FSerial.Load;
Store: @FSerial.Store
);
RSList: TStreamRec = (
ObjType: 7101;
VmtLink: Ofs(TypeOf(LSList)^);
Load: @LSList.Load;
Store: @LSList.Store
);
PROCEDURE RegisterSerial;
VAR SerialSys : PSerial;
Implementation